/**
 * @file ThreadPool.h
 * @author zeppyrz (zeppyrz@gmail.com)
 * @brief ThreadPool class
 * @version 0.1
 * @date 2025-11-03
 *
 * @copyright Copyright (c) 2025
 *
 */

#ifndef ZEDISK_THREADPOOL_H
#define ZEDISK_THREADPOOL_H

#include <memory>

#include "ExportDLL.h"


namespace ZeDisk {

// forward declaration
class Thread;
class Task;

/**
 * @brief ThreadPool 基于 Libevent
 */
class DECLSPEC ThreadPool {
 public:
  /**
   * @brief 初始化线程池，并启动线程
   *
   * @param threadCount 线程数量
   */
  virtual void Init(int threadCount) = 0;

  /**
   * @brief 分发任务到线程，使用轮询调度
   *
   * @param task 任务
   */
  virtual void Dispatch(std::shared_ptr<Task> task) = 0;

  static void Exit();
  static void Wait();

 protected:
  ThreadPool() = default;
  virtual ~ThreadPool() = default;

 public:
  ThreadPool(const ThreadPool&) = delete;
  ThreadPool& operator=(const ThreadPool&) = delete;
  ThreadPool(ThreadPool&&) noexcept = delete;
  ThreadPool& operator=(ThreadPool&&) = delete;
};

class DECLSPEC ThreadPoolFactory {
public:
  static ThreadPool *CreateThreadPool(int threadCount);
};

}  // namespace ZeDisk

#endif  // ZEDISK_THREADPOOL_H
